Skip to content

gh-145685: Avoid contention on TYPE_LOCK in super() lookups#145775

Merged
colesbury merged 3 commits intopython:mainfrom
colesbury:gh-145685-super-lookup-mro
Mar 11, 2026
Merged

gh-145685: Avoid contention on TYPE_LOCK in super() lookups#145775
colesbury merged 3 commits intopython:mainfrom
colesbury:gh-145685-super-lookup-mro

Conversation

@colesbury
Copy link
Contributor

@colesbury colesbury commented Mar 10, 2026

Copy link
Contributor

@mpage mpage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Should we add a test to the scaling benchmark that reproduces the issue?

Comment on lines +12371 to +12372
_PyThreadState_PushCStackRef(tstate, &mro_ref);
mro_ref.ref = PyStackRef_FromPyObjectNew(mro);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't need to be in this PR, but would it be worth adding another function that combines these two operations?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, makes sense.

@colesbury
Copy link
Contributor Author

This is enough to fix super() on different classes, but not enough for the straightforward super() on the same class. That'll require some additional fixes. I'll add the scaling benchmark in a follow up together with those fixes:

class Base:
    def method(self):
        return 1

class Derived(Base):
    def method(self):
        return super().method()

@register_benchmark
def super_call():
    obj = Derived()
    for _ in range(1000 * WORK_SCALE):
        obj.method()

@colesbury
Copy link
Contributor Author

Actually, maybe it's worth adding the different class benchmark now and I'll update it later.

@colesbury colesbury merged commit bdf6de8 into python:main Mar 11, 2026
48 checks passed
@colesbury colesbury deleted the gh-145685-super-lookup-mro branch March 11, 2026 11:19
@miss-islington-app
Copy link

Thanks @colesbury for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Sorry, @colesbury, I could not cleanly backport this to 3.14 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker bdf6de8c3f0c2ec0d737f38014a32c1eed02c7f1 3.14

colesbury added a commit to colesbury/cpython that referenced this pull request Mar 11, 2026
…ups (pythongh-145775)

(cherry picked from commit bdf6de8)

Co-authored-by: Sam Gross <colesbury@gmail.com>
@bedevere-app
Copy link

bedevere-app bot commented Mar 11, 2026

GH-145804 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label Mar 11, 2026
colesbury added a commit that referenced this pull request Mar 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants